package cate.game.activity.newherotrial;

import cate.common.table.activity.herotrial.HeroTrialLevelRow;
import cate.common.table.d.GDFight;
import cate.game.activity.newherotrial.data.HeroTrialLevel;
import cate.game.activity.newherotrial.msg.HeroTrialResultResp;
import cate.game.play.proce.play.PlayPO;
import cate.game.role.Role;
import cate.game.role.farm.AbstractFarmFTC;

public class HeroTrialFTC extends AbstractFarmFTC<HeroTrialActivity> {
    private HeroTrialLevelRow row;

    private HeroTrialActivity trial;

    private int activityId;

    public HeroTrialFTC(Role role, int funcId,HeroTrialLevelRow row,HeroTrialActivity trial) {
        this.funcId = funcId;
        this.row = row;
        this.trial = trial;
        this.activityId = trial.base.activityId;
        setup(role);

    }

    @Override
    protected HeroTrialActivity po(Role role) {
        return role.getActivity().getEnableActivitySingle(funcId);
    }

    @Override
    public void handleResult(Role role, PlayPO playPO) {
        super.handleResult(role, playPO);
        boolean win = playPO.winner == GDFight.Team.A;
        //活动变更那就不记录数据了
        if (trial.base.activityId != this.activityId) {
            role.sendNow(new HeroTrialResultResp(funcId, win));
            return;
        }
        if (win) {
            if (!trial.passLevels.contains(row.id)) {
                HeroTrialLevel level = trial.showOrBuildLevel(row.levelTid);
                level.passDifficulty = row.difficulty;
                if (role.getGame().table.heroTrial.level.isLastDifficulty(row)) {
                    trial.passLevel = row.levelTid;
                }
                trial.passLevels.add(row.id);
                trial.noticeUpdate();
            }
        }
        role.sendNow(new HeroTrialResultResp(funcId, win));
        //清理阵法
        role.getGame().fight.position.clearPosition(role, funcId);
    }
}
